<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        修改付款合同
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

</head>

<style>
    /* .layui-form-label {
        width: 112px !important;
    } */
    .layui-tab {
        /* text-align: left !important;
        margin: 10px 0px; */
        overflow: auto !important;
    }
    .layui-upload-file {
        height: 0 !important;
    }

    #partyBLinkmanIdDiv {
        display: flex;
        justify-content: space-between;
    }

</style>

<body>
<div class="x-body">
    <form class="layui-form layui-form-pane" id="add" lay-filter="updateInfo">
        <div class="layui-tab-content">
            <span style="font-weight:bold">基本信息</span>
            <div class="layui-form-item" style="margin-top: 8px;">
                <label class="layui-form-label">合同编号</label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="text" name="contractNum" lay-filter="contractNum" lay-verify="" placeholder="请输入合同编号" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">合同类型<span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <select name="contractType" id="contractType" lay-filter="contractType" lay-verify="required" disabled="disabled">
                    </select>
                    <!-- <input  autocomplete="off"  type="text" name="contractType" lay-filter="contractType" lay-verify="" class="layui-input" readonly="readonly"> -->
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">合同总额<span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="number" name="contractTotalAmount" lay-verify="required" lay-filter="contractTotalAmount" placeholder="合同总额/元" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">乙方名称<span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <select id="partyBId" name="partyBId" lay-filter="partyBId" lay-verify="required" disabled="disabled">
                        <!-- <option value="">请选择乙方名称</option> -->
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">关联项目<span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <select id="projectId" name="projectId" lay-filter="projectId" lay-verify="required" disabled="disabled">
                    </select>
                    <!-- <input  autocomplete="off"  type="text" name="projectId" lay-filter="projectId" lay-verify="" class="layui-input" readonly="readonly"> -->
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">签订日期</label>
                    <div class="layui-input-block">
                        <input  autocomplete="off"  type="text" name="signTime" id="signTime" lay-filter="signTime" class="layui-input" placeholder="请选择签订日期" style="width:247px;">
                    </div>
                </div>
                <div class="layui-inline">
                <label class="layui-form-label">合同周期</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="number" name="contractCycle" class="layui-input" placeholder="单位：天" style="width:245px;">
                </div>
                </div>

            </div>

            <span style="font-weight:bold">甲方乙方</span>

            <div class="layui-form-item"  style="margin-top: 8px;">
                <label class="layui-form-label">乙方联系人</label>
                <div class="layui-input-block" id="partyBLinkmanIdDiv">
                    <div style="width: 100%;">
                        <select name="partyBLinkmanId" id="partyBLinkmanId" lay-filter="" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>
                    <a title="添加人员" class="ml-5 layui-btn layui-btn-normal" onclick="add_tripartite_unit_linkman('新增人员','add_tripartite_unit_linkman.html')"><i class="layui-icon">&#xe654;</i></a>
                    <!-- <button class="layui-btn layui-btn-normal" title="新增人员" onclick="admin_add('新增人员','add_tripartite_unit_linkman.html')"><i class="layui-icon">&#xe654;</i></button> -->
                    <!-- <select name="partyBLinkmanId" id="partyBLinkmanId" lay-filter="" lay-search="" style="width: 80%;">
                        <option value="">直接选择或搜索选择</option>
                    </select>
                    <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe654;</i></button> -->
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">甲方联系人</label>
                <div class="layui-input-block">
                    <select id="partyALinkmanId" name="partyALinkmanId" lay-filter="">
                        <option value="">请选择甲方联系人</option>
                    </select>
                </div>
            </div>

            <!-- <span style="font-weight:bold">账单分期设置<span style="color: red;">*</span></span>
            <div class="layui-form-item" style="margin-top: 8px;">
            </div> -->

            <!-- <span style="font-weight:bold">附件资料</span> -->
            <!-- <button id="testList">文件上传</button> -->
            <!-- <button type="button" id="testList" style="float: right;">选择附件</button> 
            <div class="layui-form-item">
                <div class="layui-upload-list">
                    <table class="layui-table">
                        <thead>
                            <tr>
                                <th>文件名</th>
                                <th>大小</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="demoList"></tbody>
                    </table>
                </div>
            </div> -->

            <span style="font-weight:bold">备注信息</span>
            <div class="layui-form-item layui-form-text" style="margin-top: 8px;">
                <div class="layui-input-block">
                    <textarea name="memo" placeholder="合同中一些重要信息或者与甲方的约定等相关信息。" class="layui-textarea"></textarea>
                </div>
            </div>
        </div>
        <div style="text-align: center" class="layui-form-item">
            <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                保存
            </button>
        </div>
    </form>
 
</div>

<script type="text/html" id="barDemo">
    <a title="编辑" lay-event="view" class="ml-5 layui-btn-xs layui-btn" style="text-decoration:none">编辑</a>
    <a title="删除" href="javascript:;" class="layui-btn-xs layui-btn layui-btn-danger" lay-event="del"
       style="text-decoration:none">
        删除
    </a>
</script>

<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var contractId = getQueryVariable("contractId");
    var partBSelect = '';
    layui.use(['laydate', 'table','form', 'layer','upload'],
        function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;
            // var element = layui.element;
            var table = layui.table;
            var upload = layui.upload;

            laydate.render({
                elem: '#dueDate', //指定元素
                trigger: 'click',
                type: 'date',
                done: function (value, date, endDate) {
                    vm.rp.dueDate = value
                }
            });
            laydate.render({
                elem: '#signTime'
            });

            let request = {
                url: 'xa/contractInfo/findContractInfo',
                data: {
                    id:contractId,
                    userId:$userId
                },
            };
            sendRequest(request, (data) => {
                if (data.code === 0) {
                    // var contractTypeId = document.getElementById("contractType");
                    // for(i=0;i<contractTypeId.length;i++){
                    //     if(contractTypeId[i].value==data.data.contractType)
                    //         contractTypeId[i].selected = true;
                    // }
                    var contractTypeName = data.data.contractType === 1 ?"销售合同":"工程合同";
                    $("#contractType").append("<option value=\""+data.data.contractType+"\" selected>"+contractTypeName+"</option>");
                    $("#partyBId").append("<option value=\""+data.data.partyBId+"\" selected>"+data.data.partyBName+"</option>");
                    partBSelect = data.data.partyBId;
                    $("#projectId").append("<option value=\""+data.data.projectId+"\" selected>"+data.data.projectName+"</option>");
                    getPartyBLinkmanId(data.data.partyBId,data.data.partyBLinkmanId)
                    getPartyALinkmanId(data.data.partyALinkmanId)
                    // getProject(data.data.projectId,data.data.contractType);
                    form.val('updateInfo', {
                    		
                        "contractNum": data.data.contractNum,
                        // "contractType": contractTypeName,
                        "contractTotalAmount":data.data.contractTotalAmount,
                        // "projectId":data.data.projectName,
                        "signTime":data.data.signTime,
                        "contractCycle":data.data.contractCycle,
                        "memo":data.data.memo
                    });
                } else {
                    layer.alert(data.msg, {
                        icon: 2
                    })
                }
            });

            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    var val = data.field;
                    val.userId = $userId;
                    val.contractNature = 2;
                    val.id = contractId;

                    let request = {
                        url: 'xa/contractInfo/updateContractInfo',
                        data: val,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                            },
                            function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                parent.location.reload();

                            });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });

            //多文件列表示例
            var demoListView = $('#demoList')
            ,uploadListIns = upload.render({
                elem: '#testList'
                ,url: 'https://httpbin.org/post' //改成您自己的上传接口
                ,accept: 'file'
                ,multiple: true
                ,auto: false
                ,bindAction: '#testListAction'
                ,choose: function(obj){   
                    var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                    //读取本地文件
                    obj.preview(function(index, file, result){
                        var tr = $(['<tr id="upload-'+ index +'">'
                        ,'<td>'+ file.name +'</td>'
                        ,'<td>'+ (file.size/1024).toFixed(1) +'kb</td>'
                        ,'<td>等待上传</td>'
                        ,'<td>'
                            ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                            ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                        ,'</td>'
                        ,'</tr>'].join(''));
                        
                        //单个重传
                        tr.find('.demo-reload').on('click', function(){
                        obj.upload(index, file);
                        });
                        
                        //删除
                        tr.find('.demo-delete').on('click', function(){
                            delete files[index]; //删除对应的文件
                            tr.remove();
                            uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                        });
                        
                        demoListView.append(tr);
                    });
                }
                ,done: function(res, index, upload){
                    if(res.files.file){ //上传成功
                        var tr = demoListView.find('tr#upload-'+ index)
                        ,tds = tr.children();
                        tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                        tds.eq(3).html(''); //清空操作
                        return delete this.files[index]; //删除文件队列已经上传成功的文件
                    }
                    this.error(index, upload);
                }
                ,error: function(index, upload){
                    var tr = demoListView.find('tr#upload-'+ index)
                    ,tds = tr.children();
                    tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                    tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                }
            });


        });

    function admin_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    };

    //添加第三方客户的联系人弹窗
    function add_tripartite_unit_linkman(title, url, w, h) {

        if (partBSelect == '') {
            layer.msg("请先选择乙方名称！", {
                icon: 7
            });
        }else {
            x_admin_show(title, url+'?partBId='+partBSelect, w, h);
        }
        
    }

    function getPartyBLinkmanId(partyBId,partyBLinkmanId){
        document.getElementById("partyBLinkmanId").innerHTML = "";
        $.ajax({
        	type:"get",
            url:baseHead + "xa/tripartiteUnitLinkman/findTripartiteUnitLinkmanByTripartiteUnitId",
            data:{
                userId :$userId,
                tripartiteUnitId:partyBId
            },
            headers: {
                "token": $token,
            },
            success:function(res){
               	if(res.code == 0){
                    $("#partyBLinkmanId").append("<option value=''>请选择乙方联系人</option>");
                    
                    for(var i =0;i < res.data.length;i++){
                        if (partyBLinkmanId == res.data[i].id) {
                            $("#partyBLinkmanId").append("<option value=\""+res.data[i].id+"\" selected>"+res.data[i].linkmanName+"</option>");
						}else {
							$("#partyBLinkmanId").append("<option value=\""+res.data[i].id+"\">"+res.data[i].linkmanName+"</option>");
						}
                    }
                    //重新渲染
                    layui.form.render("select");
                }else{
                    layer.msg(res.message);
                }
            }
        });
    };
    function getPartyALinkmanId(partyALinkmanId){
        document.getElementById("partyALinkmanId").innerHTML = "";
        $.ajax({
        	type:"get",
            url:baseHead + "user/findUserSelect",
            data:{
                userId :$userId,
            },
            headers: {
                token: $token
            },
            success:function(res){
               	if(res.code == 0){
                    $("#partyALinkmanId").append("<option value=''>请选择甲方联系人</option>");
                    
                    for(var i =0;i < res.data.length;i++){
                        if (partyALinkmanId == res.data[i].id) {
                            $("#partyALinkmanId").append("<option value=\""+res.data[i].id+"\" selected>"+res.data[i].nickname+"</option>");
						}else {
							$("#partyALinkmanId").append("<option value=\""+res.data[i].id+"\">"+res.data[i].nickname+"</option>");
						}
                    }
                    //重新渲染
                    layui.form.render("select");
                }else{
                    layer.msg(res.message);
                }
            }
        });
    }

    const vm = new Vue({
        el: "#app",
        data: {
            projectId:[],
            rp: {
                id: null,
                billType: null,
                billAmount: null,
                dueDate: null,
                personInChargeOfTheBill: null,
                relatedCustomers: null,
                associatedItems: null,
                relatedContract: null,
                payer: null,
                remark: null,
                type: null,
                skUnit: null,
                yfDate: null,
            }
        },
        created() {

            // let request = {
            //     url: 'xa/project/findProjectListByTypeIdAndDelFlag',
            //     data: {
            //         userId: $userId,
            //         delFlag:0,
            //         businessTypeId:1
            //     },
            //     method: "get"
            // }
            // sendRequest(request, (res) => {
            //     if(res.code == 0){
            //         for(var i =0;i < res.data.length;i++){
            //             $("#projectListBycontractType").append("<option value=\""+res.data[i].id+"\">"+res.data[i].name+"</option>");
            //         }
            //         //重新渲染
            //         layui.form.render("select");
            //     }else{
            //         layer.msg(res.message);
            //     }
            // })

        },
        computed: {},
        methods: {
            
        },
        mounted() {
        },


    });

    // setTimeout(() => {
    //     //修改状态
    //     let form = layui.form;
    //     //账单类型
    //     let request = {
    //         url: 'dictionary/findDataDictionaryValue',
    //         data: {
    //             userId: $userId,
    //             label: 'BILL_TYPE'
    //         },
    //         method: "POST",
    //     };
    //     sendRequest(request, (res) => {
    //         let x = res.data;
    //         $.each(x, function (index, item) {
    //             let opt = $("<option value=" + item + ">" + item + "</option>");
    //             $("select[name=billType]").append(opt);

    //         });

    //         $("select[name=billType]").val(vm.rp.billType);

    //         form.render('select');
    //     });
    // }, 300)

</script>

</body>

</html>
